package com.starhub;


import com.starhub.engine.generator.entity.BasisInfo;
import com.starhub.engine.generator.util.EntityInfoUtil;
import com.starhub.engine.generator.util.Generator;
import com.starhub.engine.generator.util.MySqlToJavaUtil;

import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Copyright: Copyright (c) 2021
 *
 * <p>说明： 自动生成工具</P>
 */
public class MyGenerator {

        //类信息：表名、作者、类说明、最后的包名E:\work\ai\1
		public static final String fileUrl = "C:\\WEAVER\\Java\\IdeaProjects\\government-model\\src\\main\\java\\";// 生成文件存放位置
        public static final String TABLE = "sys_permission";
		public static final String AUTHOR = "luosw";//编写人git账号
		public static final String AUTHORNAME = "luosw";//编写人姓名
        public static final String CLASSCOMMENT = "权限表";
        public static final String entityNameLower = "permission";//最后的包名

		// 基础信息：项目名、版本
		public static final String PROJECT = "starhub-schema";
		public static final String VERSION = "V1.0";
		// 数据库连接信息：连接URL、用户名、秘密、数据库名
		public static final String URL = "jdbc:mysql://43.139.124.204:3317/govern?characterEncoding=utf8&useSSL=false&autoReconnect=true&failOverReadOnly=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&allowMultiQueries=true";
		public static final String NAME = "root";
		public static final String PASS = "xsAI@2025!";
		public static final String DATABASE = "govern";
		// 时间

		public static final String TIME = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime()) ;
		public static final String AGILE = new Date().getTime() + "";
		// 路径信息，分开路径方便聚合工程项目，微服务项目
		public static final String ENTITY_URL = "com.starhub.engine."+entityNameLower+".entity";
		public static final String DAO_URL = "com.starhub.engine."+entityNameLower+".dao";
		public static final String XML_URL = "resources.mapper."+entityNameLower;
		public static final String SERVICE_URL = "com.starhub.engine."+entityNameLower+".service";
		public static final String SERVICE_IMPL_URL = "com.starhub.engine."+entityNameLower+".service.impl";
		public static final String BS_CONTROLLER_URL = "com.starhub.engine."+entityNameLower+".controller";
		public static final String APP_CONTROLLER_URL = "com.starhub.app."+entityNameLower+".controller";
		public static final String US_CONTROLLER_URL = "com.starhub.api."+entityNameLower+".controller";
		public static final String REQUEST_ENTITY_URL = "com.starhub.engine."+entityNameLower+".request";//请求对象
		//是否是Swagger配置
		public static final String IS_SWAGGER = "true";
		public static final boolean isCoverFile = true;//如果目标文件已经存在，是否覆盖

	public static void main(String[] args) {
		BasisInfo bi = new BasisInfo(PROJECT, AUTHOR, VERSION, URL, NAME, PASS, DATABASE, TIME, AGILE, ENTITY_URL,
				DAO_URL, XML_URL, SERVICE_URL, SERVICE_IMPL_URL, BS_CONTROLLER_URL,APP_CONTROLLER_URL,US_CONTROLLER_URL,IS_SWAGGER,isCoverFile, entityNameLower);
		bi.setAuthorName(AUTHORNAME);
		bi.setTable(TABLE);
		String entityName = MySqlToJavaUtil.getClassName(TABLE);
		String requestEntityName = entityName+"BsRequest";
		bi.setEntityName(entityName);
		bi.setObjectName(MySqlToJavaUtil.changeToJavaFiled(TABLE));
		bi.setEntityComment(CLASSCOMMENT);
		bi.setRequestEntityUrl(REQUEST_ENTITY_URL);
		bi.setRequestEntityName(requestEntityName);

		try {
			bi = EntityInfoUtil.getInfo(bi);
			String xmlUrl = fileUrl.replace("java\\","");// 生成文件存放位置
			//开始生成文件
			String aa1 = Generator.createEntity(fileUrl, bi).toString();//bean
			String aa2 = Generator.createDao(fileUrl, bi).toString();//dao
			String aa3 = Generator.createDaoImpl(xmlUrl, bi).toString();//mapper
			String aa4 = Generator.createService(fileUrl, bi).toString();//service
			String aa5 = Generator.createServiceImpl(fileUrl, bi).toString(); //serviceImpl
			String aa6 = Generator.createBsController(fileUrl, bi).toString();//后台Controller
			String aa7 = Generator.createAppController(fileUrl, bi).toString();//APP前台Controller
			String aa8 = Generator.createUsController(fileUrl, bi).toString();//PC前台Controller
			String aa9 = Generator.createBsEntityRequest(fileUrl, bi).toString();//bsEntity

			System.out.println(aa1);
			System.out.println(aa2);
			System.out.println(aa3);
			System.out.println(aa4);
			System.out.println(aa5);
			System.out.println(aa6);
			System.out.println(aa7);
			System.out.println(aa8);
			System.out.println(aa9);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
